var rules = {
    name: {
        required: !0,
    },
    idCard: {
        required: !0
    },
}
var status;
var idCardImgInfo = ['身份证正面', '身份证背面'];

$(init);

function init() {
    document.addEventListener('init', function (event) {
        var page = event.target;
        // DATA RENDER FOR PAGE
        if (page.matches('#real-name')) {

        }
    });
}

function initStatus() {
    promise('GET', URL_BUY_INFO, null, cbInitStatus, null);
}

function cbInitStatus(e) {
    status = e.approveState >= 0 ? e.approveState : -1;
    var func;
    // status = -1
    if (status == -1 || status == null) {
        //未绑定
        func = renderTmpl(TMPL_BUY_BIND_IDCARD, {
            list: [1, 1],
            imgInfo: idCardImgInfo,
            status: -1,
        })
    } else {
        // 待审核或审核通过 显示已经绑定表单
        func = renderTmpl(TMPL_BUY_BIND_IDCARD, {
            name: cookie('name'),
            idCard: cookie('idcard'),
            idImg: [cookie('idcardpng1'), cookie('idcardpng2')],
            status: status,
            list: [1, 1],
            imgInfo: idCardImgInfo,
            type: status !== 2 ? "disabled" : null,
            statusText: AUDIT_STATUS[status],
            imgPrefix: IMG_PREFIX
        })
    }
    func.then(function(h) {
        $(".container").append(h);
        $(".fancybox").fancybox({
            'titlePosition': 'inside',
            'type': 'image'
        });
        $("#form-bind").validate({
            rules: rules,
            submitHandler: function(e) {
                doSave()
            }
        })
    })
}